package leetcode.method.pointer;

import common.bean.ListNode;

public class Program1431CycleListNode {
    public Program1431CycleListNode() {
    }


    public boolean hasCycle(ListNode head) {

        ListNode slow = head, fast = head;
        while (fast != null) {
            fast = fast.next;
            if (fast == null) {
                return false;
            }
            if (slow == fast) {
                return true;
            }
            slow = slow.next;
            fast = fast.next;
        }

        return false;
    }

    public static void main(String[] args) {
//        Program1431CycleList myStack = new Program1431CycleList();
//        int[] nums = new int[]{0,0,1,1,1,2,2,3,3,4};
//        System.out.println(myStack.hasCycle(nums)); // 返回
    }
}
